home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / manageme / tcpdump-.001 / tcpdump-~ / tcpdump-3.0.2-linux / libpcap-0.0.6 / gencode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-12  |  4.2 KB  |  174 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * @(#) $Header: gencode.h,v 1.20 94/06/12 14:29:30 leres Exp $ (LBL)
  22.  */
  23.  
  24. /*
  25.  * filter.h must be included before this file.
  26.  */
  27.  
  28. /* Address qualifers. */
  29.  
  30. #define Q_HOST        1
  31. #define Q_NET        2
  32. #define Q_PORT        3
  33. #define Q_GATEWAY    4
  34. #define Q_PROTO        5
  35.  
  36. /* Protocol qualifiers. */
  37.  
  38. #define Q_LINK        1
  39. #define Q_IP        2
  40. #define Q_ARP        3
  41. #define Q_RARP        4
  42. #define Q_TCP        5
  43. #define Q_UDP        6
  44. #define Q_ICMP        7
  45.  
  46. #define    Q_DECNET    8
  47. #define    Q_LAT        9
  48. #define    Q_MOPRC        10
  49. #define    Q_MOPDL        11
  50.  
  51. /* Directional qualifers. */
  52.  
  53. #define Q_SRC        1
  54. #define Q_DST        2
  55. #define Q_OR        3
  56. #define Q_AND        4
  57.  
  58. #define Q_DEFAULT    0
  59. #define Q_UNDEF        255
  60.  
  61. struct stmt {
  62.     int code;
  63.     long k;
  64. };
  65.  
  66. struct slist {
  67.     struct stmt s;
  68.     struct slist *next;
  69. };
  70.  
  71. /* 
  72.  * A bit vector to represent definition sets.  We assume TOT_REGISTERS
  73.  * is smaller than 8*sizeof(atomset).
  74.  */
  75. typedef u_long atomset;
  76. #define ATOMMASK(n) (1 << (n))
  77. #define ATOMELEM(d, n) (d & ATOMMASK(n))
  78.  
  79. /*
  80.  * An unbounded set.
  81.  */
  82. typedef u_long *uset;
  83.  
  84. /*
  85.  * Total number of atomic entities, including accumulator (A) and index (X).
  86.  * We treat all these guys similarly during flow analysis.
  87.  */
  88. #define N_ATOMS (BPF_MEMWORDS+2)
  89.  
  90. struct edge {
  91.     int id;
  92.     int code;
  93.     uset edom;
  94.     struct block *succ;
  95.     struct block *pred;
  96.     struct edge *next;    /* link list of incoming edges for a node */
  97. };
  98.  
  99. struct block {
  100.     int id;
  101.     struct slist *stmts;    /* side effect stmts */
  102.     struct stmt s;        /* branch stmt */
  103.     int mark;
  104.     int level;
  105.     int offset;
  106.     int sense;
  107.     struct edge et;
  108.     struct edge ef;
  109.     struct block *head;
  110.     struct block *link;    /* link field used by optimizer */
  111.     uset dom;
  112.     uset closure;
  113.     struct edge *in_edges;
  114.     atomset def, kill;
  115.     atomset in_use;
  116.     atomset out_use;
  117.     long oval;
  118.     long val[N_ATOMS];
  119. };
  120.  
  121. struct arth {
  122.     struct block *b;    /* protocol checks */
  123.     struct slist *s;    /* stmt list */
  124.     int regno;        /* virtual register number of result */
  125. };
  126.  
  127. struct qual {
  128.     unsigned char addr;
  129.     unsigned char proto;
  130.     unsigned char dir;
  131.     unsigned char pad;
  132. };
  133.  
  134. #ifndef __GNUC__
  135. #define volatile
  136. #endif
  137.  
  138. struct arth *gen_loadi(int);
  139. struct arth *gen_load(int, struct arth *, int);
  140. struct arth *gen_loadlen(void);
  141. struct arth *gen_neg(struct arth *);
  142. struct arth *gen_arth(int, struct arth *, struct arth *);
  143.  
  144. void gen_and(struct block *, struct block *);
  145. void gen_or(struct block *, struct block *);
  146. void gen_not(struct block *);
  147.  
  148. struct block *gen_scode(char *, struct qual);
  149. struct block *gen_ecode(u_char *, struct qual);
  150. struct block *gen_ncode(u_long, struct qual);
  151. struct block *gen_proto_abbrev(int);
  152. struct block *gen_relation(int, struct arth *, struct arth *, int);
  153. struct block *gen_less(int);
  154. struct block *gen_greater(int);
  155. struct block *gen_byteop(int, int, int);
  156. struct block *gen_broadcast(int);
  157. struct block *gen_multicast(int);
  158. struct block *gen_inbound(int);
  159.  
  160. void bpf_optimize(struct block **);
  161. volatile void bpf_error(char *, ...);
  162.  
  163. void finish_parse(struct block *);
  164. char *sdup(char *);
  165.  
  166. struct bpf_insn *icode_to_fcode(struct block *, int *);
  167. int pcap_parse(void);
  168. void lex_init(char *);
  169. void sappend(struct slist *, struct slist *);
  170.  
  171. /* XXX */
  172. #define JT(b)  ((b)->et.succ)
  173. #define JF(b)  ((b)->ef.succ)
  174.